package servlet.homepage;

import pojo.Commodity;
import pojo.CommodityClass;
import service.CommodityClassService;
import service.CommodityService;
import service.impl.CommodityClassServiceImpl;
import service.impl.CommodityServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 传输商品分类和商品信息数据到首页的servlet
 */
@WebServlet(value = "/DisplayServlet")
public class DisplayServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        CommodityService cs=new CommodityServiceImpl();
        CommodityClassService ccs=new CommodityClassServiceImpl();
        List<Commodity> commodities=cs.queryAllCommodity(1);
        List<Commodity> commoditiesBy110=cs.queryCommodityByClId(110,1);
        List<Commodity> commoditiesBy122=cs.queryCommodityByClId(122,1);
        List<Commodity> commoditiesBy150=cs.queryCommodityByClId(150,1);
        List<Commodity> commoditiesBy130=cs.queryCommodityByClId(130,1);
        List<Commodity> commoditiesBy140=cs.queryCommodityByClId(140,1);
        List<Commodity> commoditiesBy144=cs.queryCommodityByClId(144,1);
        List<Commodity> commoditiesBy160=cs.queryCommodityByClId(160,1);
        List<Commodity> commoditiesBy165=cs.queryCommodityByClId(165,1);
        List<Commodity> seckillCommodities=cs.querySeckillCommodity();
        List<CommodityClass> commodityClasses=ccs.queryCommodityClass();
        request.setAttribute("commodities",commodities);
        request.setAttribute("commodityClasses",commodityClasses);
        request.setAttribute("commoditiesBy110",commoditiesBy110);
        request.setAttribute("commoditiesBy122",commoditiesBy122);
        request.setAttribute("commoditiesBy150",commoditiesBy150);
        request.setAttribute("commoditiesBy130",commoditiesBy130);
        request.setAttribute("commoditiesBy140",commoditiesBy140);
        request.setAttribute("commoditiesBy144",commoditiesBy144);
        request.setAttribute("commoditiesBy160",commoditiesBy160);
        request.setAttribute("commoditiesBy165",commoditiesBy165);
        request.setAttribute("seckillCommodities",seckillCommodities);
        request.getRequestDispatcher("/PrimaryPage.jsp").forward(request,response);
    }
    
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
        doGet(request, response);
    }
}
